package com.qqtech.qquan.order.service;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.qqtech.core.frame.dao.BaseDao;
import com.qqtech.core.frame.service.BaseServiceImpl;
import com.qqtech.qquan.order.dao.OrderPayLogDao;
import com.qqtech.qquan.order.enums.OrderPayWayDictEnum;
import com.qqtech.qquan.order.model.OrderPayLog;
import com.qqtech.qquan.order.model.OrderPayLogQuery;
import com.qqtech.qquan.order.model.OrderPayLogVo;

@Service
public class OrderPayLogServiceImpl extends BaseServiceImpl<OrderPayLog> implements OrderPayLogService {
	public static final Logger log = LoggerFactory.getLogger(OrderPayLogServiceImpl.class);

	@Resource
	private OrderPayLogDao orderPayLogDao;

	@Override
	protected BaseDao<OrderPayLog> getBaseDao() {
		return orderPayLogDao;
	}

	@Override
	public BigDecimal getPayedByOrderNo(String orderNo, OrderPayWayDictEnum payWay) {
		BigDecimal bd = BigDecimal.ZERO;
		OrderPayLog orderPayLog = new OrderPayLog();
		orderPayLog.setOrderNo(orderNo);
		if (payWay != null) {
			orderPayLog.setPayWay(payWay.getCode());
		}
		List<OrderPayLog> listOrderPayLog = orderPayLogDao.queryList(orderPayLog);
		if (listOrderPayLog != null && listOrderPayLog.size() > 0) {
			for (OrderPayLog orderPayLog2 : listOrderPayLog) {
				if (orderPayLog2.getValue() != null) {
					bd = bd.add(orderPayLog2.getValue());
				}
			}
		}
		return bd;
	}

	@Override
	public BigDecimal getShopDiscountByOrderNo(String orderNo, OrderPayWayDictEnum payWay) {
		BigDecimal bd = BigDecimal.ZERO;
		OrderPayLog orderPayLog = new OrderPayLog();
		orderPayLog.setOrderNo(orderNo);
		if (payWay != null) {
			orderPayLog.setPayWay(payWay.getCode());
		}
		List<OrderPayLog> listOrderPayLog = orderPayLogDao.queryList(orderPayLog);
		if (listOrderPayLog != null && listOrderPayLog.size() > 0) {
			for (OrderPayLog orderPayLog2 : listOrderPayLog) {
				if (orderPayLog2.getShopDiscountValue() != null) {
					bd = bd.add(orderPayLog2.getShopDiscountValue());
				}
			}
		}
		return bd;
	}

	@Override
	public int queryCountAdmin(OrderPayLogQuery query) {
		return orderPayLogDao.queryCountAdmin(query);
	}

	@Override
	public Page<OrderPayLogVo> queryPageListAdmin(OrderPayLogQuery query, Pageable pageable) {
		return orderPayLogDao.queryPageListAdmin(query, pageable);
	}

	@Override
	public List<OrderPayLogVo> queryListAdmin(OrderPayLogQuery query, Pageable pageable) {
		return orderPayLogDao.queryListAdmin(query, pageable);
	}
}